import { JSONMapping } from "../json-mapping";
import { SyncStatus } from "../sync-status";
import {ObjectDtoInterface} from "../../services/sqliteDB/object.dto";

export class Attachment extends JSONMapping implements ObjectDtoInterface {
    static PropertyKeyToJSONKeyMap() {
        return {};
    }

    static useAttachmentIdsAndThumbnailIdsGetAttachments(attachmentIds, thumbnailIds, noCheckoutThumbnailIds = false) {
      let thumbnailIdsArray = [];
      if (noCheckoutThumbnailIds) {
        if (!attachmentIds) {
          return [];
        }
      } else {
        if (!attachmentIds || !thumbnailIds) {
          return [];
        }
        thumbnailIdsArray = thumbnailIds.split(',');
      }
      let attachmentIdsArray = attachmentIds.split(',');
      let attachments = attachmentIdsArray.map((attachmentId, index) => {
        return {
          id: attachmentId,
          thumbnailId: thumbnailIdsArray[index]
        };
      });
      return attachments.map((attachment) => {
        return new Attachment(attachment);
      });
    }

    public id: string = null;
    public billId: string = null;
    public thumbnailId: string = null; // 缩略图Id
    public attachmentName: string = null; // 附件名
    public path: string = null; // 附件路径
    public syncStatus: SyncStatus = SyncStatus.None; // 编号


    constructor(json: { [key: string]: any }) {
        super(json);
        Attachment.mapFromJSON(json, this);
    }


}

